from openai import OpenAI

client = OpenAI(api_key="sk-8aeced12e2ff4ae9aa52ee208ea19b47", base_url="https://api.deepseek.com")


def generate_synonyms(question_item, count=3):
    """
    Generate 3 synonyms for a given word using the deepseek-chat model.
    :param question_item:
    :return:
    """
    response = client.chat.completions.create(
        model="deepseek-chat",
        messages=[
            {"role": "system", "content": f"你是一个同义词生成助手，请为给定的词生成 {count} 个同义词。格式为：词1|词2|词3"},
            {"role": "user", "content": f"请为以下词生成 {count} 个同义词：'{question_item}'"}
        ],
        stream=False
    )
    # 提取生成的同义词
    generated_text = response.choices[0].message.content
    # print(generated_text)
    synonyms = [s.strip() for s in generated_text.split("|") if s.strip()]
    return synonyms


# print(generate_synonyms("苹果",4))